package com.qf.controller;

import com.qf.pojo.Address;
import com.qf.pojo.User;
import com.qf.service.AddressService;
import com.qf.service.impl.AddressServiceImpl;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 消费者地址管理
 * @author 千锋健哥
 */
@WebServlet("/address")
public class AddressController extends BaseController{

    /**
     * 查询地址列表
     * @param request
     * @param response
     * @return
     */
    public String show(HttpServletRequest request, HttpServletResponse response) {
        //1. 从会话中获取用户登录的对象信息
        User user = (User)request.getSession().getAttribute("loginUser");
        //2. 判断如果用户对象获取不到, 说明用户未登录, 或者登录超时, 跳转到登录页面
        if (user == null) {
            return "redirect:/login.jsp";
        }
        //3. 调用service, 根据用户id查询收货地址列表
        AddressService addressService = new AddressServiceImpl();
        List<Address> list = addressService.findList(user.getId());
        //4. 将数据放入请求域中
        request.setAttribute("list", list);

        //5. 跳转到地址列表页面
        return "forward:/self_info.jsp";

    }
}
